package pluginMain;

import pluginMain.Lore;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.configuration.ConfigurationSection;

public class EffectsLib {
	private Map<String, Effect> effects = new HashMap<String, Effect>();
	private Configer loreFile;

	public EffectsLib() {
		// Load Effect from Config
		loreFile = new Configer(Lore.instance, "LoreEffect.yml");
		for (String name : loreFile.getKeys(false)) {
			Effect effect = new Effect(name, Effect.EffectType.valueOf(loreFile.getString(name + ".effect")));
			effects.put(name, effect);
			ConfigurationSection levelSection = loreFile.getConfigurationSection(name + ".grades");
			for (String formatedLevel : levelSection.getKeys(false)) {
				effect.addLevel(formatedLevel, levelSection.getInt(formatedLevel));
				Lore.LOGCONSOLE(
						"Lore:" + name + " Level:" + formatedLevel + " Effect:" + levelSection.getInt(formatedLevel));
			}
		}
		Lore.LOGCONSOLE("Loaded " + effects.size() + " Lore from Config.");
	}

	public Effect getEffectByName(String name) {
		return effects.get(name).clone();
	}
}
